﻿using System;
using System.Collections.Generic;
using System.Linq;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectTaskHandler
{
    public class GetProjectTaskToList
    {
        private readonly ProjectTaskRepository _projectTaskRepository;

        public GetProjectTaskToList(ProjectTaskRepository projectTaskRepository)
        {
            _projectTaskRepository = projectTaskRepository;
        }
        public GetProjectTaskToList()
        {
            _projectTaskRepository = new ProjectTaskRepository();
        }
        public virtual IEnumerable<ProjectTaskModel> Execute(int? projectId)
        {
            IEnumerable<ProjectTaskModel> projectTasksModels = null;
            /**try
            {
                // try to get from db
                IEnumerable<TASK> projectTasksData = _projectTaskRepository.GetProjectTasks(projectId, categoryId);

                // parse to business model
                if(projectTasksData != null && projectTasksData.Count() > 0)
                {
                    projectTasksModels = from prjTask in projectTasksData
                                            select new ProjectTaskModel(prjTask);
                }
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }**/

            try
            {
                // try to get from db
                IEnumerable<TASK> projectTasksData = _projectTaskRepository.GetProjectTasks(projectId);

                // parse to business model
                if(projectTasksData != null && projectTasksData.Count() > 0)
                {
                    projectTasksModels = from prjTask in projectTasksData
                                            select new ProjectTaskModel(prjTask);
                }
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }



            return projectTasksModels;

        }
    }
}
